/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sistema.aplicacao;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JWindow;
import javax.swing.SwingConstants;

/**
 *
 * @author gr
 */
public class WindowScreen extends JWindow
{

    private JProgressBar barra;
    private ImageIcon img;
    private javax.swing.Timer activityMonitor;
    private ThreadAtualiza activity;
    FormPrincipal principal;


    public WindowScreen(int id, String nome, String tipo_usuario, String login )
    {

        principal = new FormPrincipal( id, nome, tipo_usuario, login );


        setSize( 400, 250 );
        setLocationRelativeTo( null );
        iniciaComponentes();
        barra();
        setVisible( true );

    }


    public void iniciaComponentes()
    {


        setLayout( new GridBagLayout() );

        //Label
        add( new JLabel( "<html><h3>Controle de Ligações Suporte</h3></html>", SwingConstants.CENTER ),
                new GridBagConstraints( 1,0,3,1,0.5,0.5,
                GridBagConstraints.CENTER, GridBagConstraints.CENTER,
                new Insets( 15, 5, 5, 5 ),0,0) );


        //Imagem
        img = new ImageIcon( getClass().getResource( "/img/img.png" ) );
        
        add( new JLabel( img ), new GridBagConstraints( 2,1,2,1,0.5, 5.0,
                GridBagConstraints.CENTER, GridBagConstraints.CENTER,
                new Insets( 0, 5, 15, 5 ),0,0) );

        //Barra
        barra = new JProgressBar();
        barra.setPreferredSize( new Dimension( 10, 10));

        add( barra, new GridBagConstraints( 0,2,4,1,0.5,0.1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
                new Insets( 5, 10, 15, 10 ),0,0) );

        barra.setMinimum( 0 );
        barra.setStringPainted( false );
        barra.setBackground( Color.GRAY );

        activityMonitor = new javax.swing.Timer( 100,
                new ActionListener()
                {

                    public void actionPerformed( ActionEvent event )
                    {
                        int current = activity.getCurrent();

                        // show progress
                        barra.setValue( current );

                        // check if task is completed
                        if ( current == activity.getTarget() )
                        {
                            activityMonitor.stop();;
                            dispose();

                            principal.setVisivel( true );

                            
                        }
                    }
                } );



    }


    public void barra()
    {
        barra.setMaximum( 1000 );
        activity = new ThreadAtualiza( 1000 );
        activity.start();
        activityMonitor.start();

    }
}
